//
//  remaiTableViewCell.m
//  lmq
//
//  Created by 千翼网络科技 on 2017/1/17.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "remaiTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "RemaiCollectionViewCell.h"
#import "detailsViewController.h"
#import "goodsViewController.h"
@implementation remaiTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor=[ZJCModel colorWithString:@"222222"];
        

//        UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
//        layout.minimumLineSpacing = 10;
//        layout.minimumInteritemSpacing = 10;
//        layout.itemSize = CGSizeMake(DEF_SCREEN_WIDTH , 270);
//        //直接布局 上下左右
//        layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
//        
//        goodsCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT*20) collectionViewLayout:layout];
//        goodsCollectionView.delegate=self;
//        goodsCollectionView.dataSource=self;
//        goodsCollectionView.scrollEnabled = NO;
//        goodsCollectionView.alwaysBounceVertical = YES;
//        goodsCollectionView.backgroundColor= [UIColor whiteColor];
//        [goodsCollectionView registerClass:[RemaiCollectionViewCell class] forCellWithReuseIdentifier:@"RemaiCollectionViewCell"];
//        [self addSubview:goodsCollectionView];
        
    }
    return self;
}

- (void)setNum:(NSString *)num{

    _num = num;
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    //    layout.minimumLineSpacing = 10;
    //    layout.minimumInteritemSpacing = 10;
    layout.itemSize = CGSizeMake(DEF_SCREEN_WIDTH , 285);
    //直接布局 上下左右
    //  layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    goodsCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 305*[_num intValue]) collectionViewLayout:layout];
    goodsCollectionView.delegate=self;
    goodsCollectionView.dataSource=self;
    goodsCollectionView.scrollEnabled = NO;
    goodsCollectionView.alwaysBounceVertical = YES;
    goodsCollectionView.backgroundColor= [UIColor whiteColor];
    [goodsCollectionView registerClass:[RemaiCollectionViewCell class] forCellWithReuseIdentifier:@"RemaiCollectionViewCell"];
    [self addSubview:goodsCollectionView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - CollectionView ---------------------------------------
//section 的个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//cell的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    NSLog(@"%@", myarr);
    return myarr.count;
    
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identify = @"RemaiCollectionViewCell";
    
    RemaiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];

    NSMutableDictionary *dict2=myarr[indexPath.row];
    cell.titleLabel.text=[dict2 objectForKey:@"name"];
    NSString *str = @"¥";
    
    cell.moneyLable.text= [str stringByAppendingString:[dict2 objectForKey:@"price"]];
    cell.moneyLable.textColor = [UIColor redColor];
    cell.moneyLable.textAlignment = NSTextAlignmentRight;
    
    NSString *urlWare=[dict2 objectForKey:@"pic"];
    NSString *urlN=manage(AP_HOST, urlWare);
    NSLog(@"QQQQQQQQQQQQQQQQQQQQQQQQQQQQQ%@",dict2);
    NSString *strUrl = [urlN stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    NSURL *urlW=[NSURL URLWithString:strUrl];
    [cell.imageshow sd_setImageWithURL:urlW placeholderImage:[UIImage imageNamed:@"niunai"]];
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
   
    
    goodsViewController *detailsVC=[[goodsViewController alloc]init];


    NSDictionary *aDict=myarr[indexPath.row];
    detailsVC.myStr=[aDict objectForKey:@"card_id"];
    detailsVC.tittleStr = [aDict objectForKey:@"card_name"];
    [((homeViewController *)self.VC).navigationController pushViewController:detailsVC animated:YES];
    
}

#pragma mark -- UICollectionViewDelegate




-(void)updateInfo:(NSArray*)SDCycleArr{
    
    myarr=[[NSMutableArray alloc]init];
    for (int i=0; i<SDCycleArr.count; i++) {

        myarr=SDCycleArr;
    }
    [goodsCollectionView reloadData];
}



@end
